package Q303

/**
 * 区域和检索 - 数组不可变
 * @author 23738
 * @date 2022.5.8
 */
class Main {

}

fun main() {

}


class Solution {
    fun diStringMatch(s: String): IntArray {
        var i = 0
        var j = s.length
        val res = IntArray(s.length + 1)
        var resIdx = 0
        var idx = 0
        while (i < j) {
            if (s[idx] == 'I') {
                res[resIdx++] = i
                i++
            } else {
                res[resIdx++] = j
                j--
            }
            idx++
        }
        res[resIdx] = j
        return res
    }
}

